<?php
// +----------------------------------------------------------------------
// | 众联TK架构 [ ZoomTk ]
// +----------------------------------------------------------------------
// | 版权所有 2017~2037 成都众联思索科技有限公司 [ http://www.zoomtk.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://www.sopvip.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

// 门户模块公共函数库
use think\Db;
/**
 * 价格格式化
 *
 * @param int $price
 * @return string    $price_format
 */
function priceFormat($price)
{
    $price_format = number_format($price, 2, '.', '');
    return $price_format;
}
/**
 * 价格格式化
 *
 * @param int $price
 * @return string    $price_format
 */
function PriceFormatForList($price)
{
    if ($price >= 10000) {
        return number_format(floor($price / 100) / 100, 2, '.', '') . L('ten_thousand');
    } else {
        return L('currency') . $price;
    }
}
/**
 * 商品二维码
 * @param array $goods_info
 * @return string
 */
function goodsQRCode($goods_info)
{
    if (!file_exists(BASE_UPLOAD_PATH . '/' . ATTACH_STORE . '/' . $goods_info['store_id'] . '/' . $goods_info['goods_id'] . '.png')) {
        return UPLOAD_SITE_URL . DS . ATTACH_STORE . DS . 'default_qrcode.png';
    }
    return UPLOAD_SITE_URL . DS . ATTACH_STORE . DS . $goods_info['store_id'] . DS . $goods_info['goods_id'] . '.png';
}

function orderState($order_info)
{
    switch ($order_info["order_state"]) {
        case ORDER_STATE_CANCEL:
            $order_state = "已取消";
            break;

        case ORDER_STATE_NEW:
            $order_state = "待付款";
            break;

        case ORDER_STATE_PAY:
            $order_state = "待发货";
            break;

        case ORDER_STATE_SEND:
            $order_state = "待收货";
            break;

        case ORDER_STATE_SUCCESS:
            $order_state = "交易完成";
            break;
    }
    return $order_state;
}

function orderPaymentName($payment_code)
{
    return str_replace(array("offline", "online", "alipay", "tenpay", "chinabank", "predeposit", "wxpay", 'chain'), array("货到付款", "在线付款", "支付宝", "财付通", "网银在线", "站内余额支付", "微信支付", '门店付款'), $payment_code);
}

function orderGoodsType($goods_type)
{
    return str_replace(array("1", "2", "3", "4", "5", "8", "9"), array("", "团购", "限时折扣", "优惠套装", "赠品", "", "换购"), $goods_type);
}

function billState($bill_state)
{
    return str_replace(array("1", "2", "3", "4"), array("已出账", "商家已确认", "平台已审核", "结算完成"), $bill_state);
}

/**
 * 验证是否为平台店铺
 *
 * @return boolean
 */
function checkPlatformStore(){
    return session('is_own_shop');
}

/**
 * 验证是否为平台店铺 并且绑定了全部商品类目
 *
 * @return boolean
 */
function checkStoreBindingAllGoodsClass(){
    return checkPlatformStore() && session('is_own_shop');
}

/**
 * 返回以原数组某个值为下标的新数据
 *
 * @param array $array
 * @param string $key
 * @param int $type 1一维数组2二维数组
 * @return array
 */
function array_under_reset($array, $key, $type=1){
    if (is_array($array)){
        $tmp = array();
        foreach ($array as $v) {
            if ($type === 1){
                $tmp[$v[$key]] = $v;
            }elseif($type === 2){
                $tmp[$v[$key]][] = $v;
            }
        }
        return $tmp;
    }else{
        return $array;
    }
}